<#systemSituation globalInfo="${globalInfo}"/>
<link rel="stylesheet" href="/static/css/metroStyle.css">
<!-- widget grid -->
<section>

    <!-- row -->
    <div class="row">

        <!-- NEW WIDGET START -->
        <article class="col-xs-12 col-sm-12 col-md-12 col-lg-12">

            <div class="jarviswidget jarviswidget-color-blueDark" data-widget-editbutton="false">
                <header>
                    <span class="widget-icon"> <i class="fa fa-table"></i> </span>

                    <h2>参数列表 </h2>

                </header>

                <div>

                    <!-- widget edit box -->
                    <div class="jarviswidget-editbox">
                        <!-- This area used as dropdown edit box -->
                    </div>
                    <!-- end widget edit box -->

                    <!-- widget content -->
                    <div class="inbox-body no-content-padding" id="paramPage">
                        <div class="inbox-side-bar bordered" style="padding-left: 4px;">
                            <div id="paramTree" class="ztree">
                            </div>
                        </div>
                        <div class="table-wrap custom-scroll animated fast fadeInRight">
                        </div>

                    </div>

                </div>
            </div>

        </article>
        <!-- WIDGET END -->
    </div>
    <!-- end row -->
</section>
<div id="menu-icon-dialog"></div>
<!-- end widget grid -->

<script type="text/javascript">

    /* DO NOT REMOVE : GLOBAL FUNCTIONS!
     *
     * pageSetUp(); WILL CALL THE FOLLOWING FUNCTIONS
     *
     * // activate tooltips
     * $("[rel=tooltip]").tooltip();
     *
     * // activate popovers
     * $("[rel=popover]").popover();
     *
     * // activate popovers with hover states
     * $("[rel=popover-hover]").popover({ trigger: "hover" });
     *
     * // activate inline charts
     * runAllCharts();
     *
     * // setup widgets
     * setup_widgets_desktop();
     *
     * // run form elements
     * runAllForms();
     *
     ********************************
     *
     * pageSetUp() is needed whenever you load a page.
     * It initializes and checks for all basic elements of the page
     * and makes rendering easier.
     *
     */
    pageSetUp();

    /*
     * ALL PAGE RELATED SCRIPTS CAN GO BELOW HERE
     */
    // PAGE RELATED SCRIPTS
    // pagefunction
    var pagefunction = function () {

        var $page = $('#paramPage');

        // fix table height
        tableHeightSize();

        $(window).resize(function () {
            tableHeightSize()
        });

        // 发送请求，取得param的数据
        $.ajax({
            url: '${ctx}/tools/param/treeData',
            type: 'post',
            // json格式要求严格验证
            dataType: "json",
            success: function (result) {
                build(result);
            },
            error: function (xhr, error) {
                console.info('tree load data error.' + error);
            }
        });

        /**
         * 构造树
         */
        function build(zNodes) {
            // tree params
            var setting = {
                view: {
                    selectedMulti: false, dblClickExpand: false,
                    nameIsHTML: true,
                    showIcon: false,
                    showTitle: false
                },
                // 因为是有添加操作的,所以增加异步加载
                async: {
                    enable: true,
                    url: "${ctx}/tools/param/treeData",
                    dataType: "json",
                    autoParam: ["id"]
                },
                check: {
                    enable: false
                },
                // {id, pId, name}
                data: {simpleData: {enable: true}},
                callback: {
                    onClick: function (event, treeId, treeNode) {debugger;
                        // 获取当前节点下的列表
                        if (treeNode && treeNode.type != null) {
                            if (treeNode.type == 0 || treeNode.type == 1 || treeNode.type == 2) {
                                if (treeNode.isEditNode == true) {
                                    // group
                                    treeNode.isEditNode = false;
                                    // param
                                    loadURL('${ctx}/tools/param/form?id=' + encodeURIComponent(treeNode.id) +
                                            '&parentId=' + encodeURIComponent(treeNode.selectParentId),
                                            $page.find(' > .table-wrap'));
                                } else {
                                    loadURL('${ctx}/tools/param/table?id=' + encodeURIComponent(treeNode.id),
                                            $page.find(' > .table-wrap'));
                                }

                            } else {
                                // param
                                loadURL('${ctx}/tools/param/form?id=' + encodeURIComponent(treeNode.id) +
                                        '&parentId=' + encodeURIComponent(treeNode.selectParentId),
                                        $page.find(' > .table-wrap'));
                            }
                        }
                    }
                }
            };
            // 初始化树结构
            var paramTree = $.fn.zTree.init($('#paramTree'), setting, zNodes);

            // 默认展开一级节点
            var nodes = paramTree.getNodesByParam("level", 0);
            for (var i = 0; i < nodes.length; i++) {
                paramTree.expandNode(nodes[i], true, false, false);
            }
            // 默认选中根节点
            var node = paramTree.getNodeByParam("id", "1");
            if (node) {
                paramTree.selectNode(node);
                $("#" + node.tId + "_a").click();
            }
        }
    };

    // destroy generated instances
    // pagedestroy is called automatically before loading a new page
    // only usable in AJAX version!
    var pagedestroy = function () {
        // 销毁
    };
    // end destroy

    // load related plugins
    loadScript("/static/js/plugin/jquery-tree/jquery.ztree.all-3.5.js", function () {
        loadScript("/static/js/plugin/jquery-tree/jquery.ztree.exhide-3.5.js", pagefunction);
    });

</script>